package cn.smart.rest.controller;

import cn.smart.pojo.Garden;
import cn.smart.service.GardenService;
import cn.smart.util.SmartResult;
import org.apache.http.cookie.SM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Xiezh
 * @Description:花园的操作
 * @create 2017/8/15
 */
@Controller
@RequestMapping(value = "/garden")
public class GardenController {
    @Autowired
    private GardenService gardenService;

    //新增花园
    @RequestMapping(value = "/add")
    @ResponseBody
    public SmartResult addGarden(Garden garden) {
        SmartResult smartResult = gardenService.insertGarden(garden);
        return smartResult;
    }

    //删除花园
    @ResponseBody
    @RequestMapping(value = "/remove")
    public SmartResult removeGarden(@RequestParam(defaultValue = "0") int gid) {
        SmartResult smartResult = gardenService.deleteGarden(gid);
        return smartResult;
    }

    //更新花园信息
    @ResponseBody
    @RequestMapping(value = "update")
    public SmartResult updateGarden(Garden garden) {
        return gardenService.updateGarden(garden);

    }

    //查询用户名下的所有花园
    @ResponseBody
    @RequestMapping(value = "/getUserAllGarden/{uid}")
    public SmartResult getUserAllGarden(@PathVariable(value = "uid") int uid) {

        return gardenService.getUsersAllGarden(uid);
    }

    //根据花园主键查询花园
    @ResponseBody
    @RequestMapping("/getGardenByGid/{gid}")
    public SmartResult getGardenByGid(@PathVariable(value = "gid") int gid) {
        return gardenService.getGardenByGid(gid);
    }

    //根据花园mac地址查询花园
    @ResponseBody
    @RequestMapping("/getGardenByGmac/{gmac}")
    public SmartResult getGardenByGid(@PathVariable(value = "gmac") String gmac) {
        return gardenService.getGardenByGmac(gmac);
    }

}
